﻿using System;
using System.Collections.Generic;
using FireFly;
using System.Reflection;
using System.Collections;
using System.Windows;

namespace XAMLStylePad.ViewModels
{
    public class PropertyViewModel : VariableViewModel
    {
        PropertyInfo _prop;
        public PropertyViewModel(PropertyInfo prop)
        {
            _prop = prop;
        }

        internal void SetValueForInstance(object newObj)
        {
            _prop.SetValue(newObj, Value, null);
        }

        public override string Name
        {
            get
            {
                return _prop.Name;
            }
        }

        public override Type Type
        {
            get 
            { 
                return _prop.PropertyType; 
            }
        }

        public override bool IsReadOnly
        {
            get
            {
                return _prop.CanWrite;
            }
        }
    }

    public class FieldViewModel : VariableViewModel
    {
        FieldInfo _field;

        public FieldViewModel(FieldInfo info)
        {
            _field = info;
        }

        public override Type Type
        {
            get { return _field.FieldType; }
        }

        public override string Name
        {
            get { return _field.Name; }
        }

        public override bool IsReadOnly
        {
            get { return _field.IsPublic; }
        }

        internal void SetValueForInstance(object newObj)
        {
            _field.SetValue(newObj, Value);
        }
    }

}